<template>
  <div id="app">
    <router-view></router-view>
    <loading v-show="isShowLoading"></loading>
    <div class="null" v-show="isAppShow"></div>
  </div>
</template>

<script>
import { requestMe, requestJssdk } from './api/api'
import bus from './bus'
export default {
  name: 'app',
  data () {
    return {
      isShowLoading: false,
      isAppShow: true
    }
  },
  watch: {
    '$route': function () {
      this.routeChange()
    }
  },
  methods: {
    routeChange () {
      const ua = navigator.userAgent
      if (ua.indexOf('Android') > -1 || ua.indexOf('Linux') > -1) {
        this.toGetwxConfig()
      }
      const accessToken = this.$route.query.accessToken
      if (accessToken) {
        window.localStorage.setItem('accessToken', accessToken)
        const user = requestMe()
        return user
      }
    },
    toGetwxConfig: function () {
      let e = this
      requestJssdk({}).then(function (res) {
        e.r = res.data
        window.wx.config({
          debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
          appId: res.data.appId, // 必填，公众号的唯一标识
          timestamp: e.r.timestamp, // 必填，生成签名的时间戳
          nonceStr: e.r.nonceStr, // 必填，生成签名的随机串
          signature: e.r.signature, // 必填，签名，见附录1
          jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone'] // 分享到朋友圈 分享给朋友
        })
      })
    }
  },
  created () {
    this.routeChange()
    bus.$on('toggleLoading', (show) => {
      this.isShowLoading = show
    })
    bus.$on('isAppShow', (show) => {
      this.isAppShow = show
    })
  },
  mounted () {
    this.toGetwxConfig()
  }
}
</script>

<style lang="less">
  @in:30.5rem;
  @border:#e8e8e8;
  @font:#8e8e8e;
  @orange:#f1ae9b;
  .null{
    width: 100%;
    height: 100%;
    background: #fff;
    position: fixed;
    left:0;
    top:0;
  }
</style>
